</html>
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>明德人才管理系统</title>
  <link rel="stylesheet" href="/layui-v2.6.8/layui/css/layui.css">
  <style>
    .c-gray {
      color: #ccc;
    }

    .c-green {
      color: green;
    }

    .c-red {
      color: red;
    }

    .box {
      display: flex;
      justify-content: center;
    }
  </style>
</head>

<body>
  <div class="layui-layout layui-layout-admin">
    <!-- 头部 -->
    {{include'./Public_documents/header.html'}}

    <!-- 左侧 -->
    {{include'./Public_documents/Left_menu.html'}}

    <div class="layui-body">
      <!-- 内容主体区域 -->
        <div style="padding: 15px;">
          <!-- 为ECharts准备一个具备大小（宽高）的Dom -->
          <div id="main" style="width: 1000px;height:400px;"></div>

        </div>

    </div>
    {{include'./Public_documents/bottom.html'}}


  </div>
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script src="/layui-v2.6.8/layui/layui.js"></script>
  <script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>

  <script>
    //JS 
    layui.use(['element', 'layer', 'util'], function () {
      var element = layui.element,
        layer = layui.layer,
        util = layui.util,
        $ = layui.$;

      //头部事件
      util.event('lay-header-event', {
        //左侧菜单事件
        menuLeft: function (othis) {
          layer.msg('展开左侧菜单的操作', {
            icon: 0
          });
        },
        menuRight: function () {
          layer.open({
            type: 1,
            content: '<div style="padding: 15px;">处理右侧面板的操作</div>',
            area: ['260px', '100%'],
            offset: 'rt' //右上角
              ,
            anim: 5,
            shadeClose: true
          });
        }
      });

    });



    function loadGraph(cates, count) {
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById('main'));

      // 指定图表的配置项和数据
      var option = {
        title: {
          text: '文章数统计'
        },
        tooltip: {},
        legend: {
          data: ['篇数']
        },
        xAxis: {
          data: cates
        },
        yAxis: {},
        series: [{
          name: '篇数',
          type: 'bar',
          data: count
        }]
      };
      myChart.setOption(option);
    }
    //初始化数据
    function initData(){
    let names = [];
    let counts = [];
    // 发送ajax请求,获取文章分类总数
    $.get('/ClassificationDataSheet',res=>{
      // console.log(res);
      res.forEach(item => { 
        if(item.name){
          names.push(item.name)
          counts.push(item.count)
        }
      })
      console.log(names,counts)
      // 渲染图表
      loadGraph(names,counts)
    },'json')
  }
  initData()
  </script>

</body>

</html>